home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / handson / Java / SCAdventure / Implementer.java < prev    next >
Encoding:
Java Source  |  1998-04-29  |  1.5 KB  |  60 lines

  1. import java.lang.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Implementer extends java.lang.Object 
  6.    implements AdventureConstants
  7. {
  8.     // This is the Control Centre of the Adventure - the
  9.     // main non-visual unit. It creates the Adventure and
  10.     // looks after other essential tasks such as 
  11.     // saving and restoring.
  12.     
  13.     // Create the Adventure
  14.     private Adventure Adv = new Adventure();
  15.     
  16.     Implementer() {
  17.     }
  18.     
  19.     // HANDLE THE ADVENTURE OBJECT
  20.     Adventure getAdv() {
  21.         return Adv;
  22.     }
  23.     
  24.     // Save
  25.     String SaveAdv(String filename) {
  26.         // return String indicating success (or otherwise) of Save operation
  27.         String s = "\nFile Saved";
  28.         try {
  29.             FileOutputStream fos = new FileOutputStream(filename);
  30.             ObjectOutputStream oos = new ObjectOutputStream( fos );
  31.             oos.writeObject( Adv );
  32.             oos.flush(); // write out any buffered bytes
  33.         }
  34.         catch (Exception e) {
  35.             s = "\nSerialization Error! Can't save data.";
  36.         }
  37.         return s;
  38.     }
  39.  
  40.     // Load
  41.     String LoadAdv(String filename) {
  42.         // return String indicating success (or otherwise) of Load operation
  43.         String s = "\nFile Loaded";
  44.         try {
  45.             FileInputStream fis = new FileInputStream(filename);
  46.             ObjectInputStream ois = new ObjectInputStream( fis );
  47.             Adv = (Adventure) ois.readObject( );
  48.         }
  49.         catch (Exception e) {
  50.             s = "\nSerialization Error! Can't load data.";
  51.         }        
  52.         return s;
  53.     }
  54.     
  55.     
  56.  
  57.  
  58.  
  59. }
  60.